package com.ljc.dao;

import com.ljc.entity.Expert;
import com.ljc.entity.ExpertGradeCount;
import com.ljc.vo.ExpertSearch;
import org.apache.catalina.LifecycleState;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
@Mapper
@Repository
public interface ExpertDao {
    List<Expert> searchExpert(ExpertSearch expertSearch);

    @Select("select grade, count(*) count\n" +
            "from expert \n" +
            "where dean_id=#{deanId} and deleted=0 \n" +
            "group by grade")
    List<ExpertGradeCount>  getExpertGradeCount(int deanId);

    @Select("select * from expert where name=#{username}")
    Expert getOne(String username);

    @Insert("insert into expert(name,password,realname,sex,grade,organization,phone,email,status,dean_id) " +
            "values(#{name},#{password},#{realName},#{sex},#{grade},#{organization},#{phone},#{email},#{status},#{deanId})")
    void addOne(Expert expert);

    @Select("select * from expert where id=#{id}")
    Expert findExpertById(int id);

    @Update("update expert set name=#{name},password=#{password},realname=#{realName},sex=#{sex},grade=#{grade},organization=#{organization},phone=#{phone},email=#{email},status=#{status}" +
            " where id=#{id}")
    void updateExpert(Expert expert);

    //删除用户：修改标记位
    @Update("update expert set deleted=1 where id=#{id}")
    void deleteExpert(int id);

    //获取激活状态的专家
    @Select("select * from expert where deleted=0 and status=1 and dean_id=#{deanId}")
    List<Expert> getActiveExpert(int deanId);

}
